package com.ruoyi.yuan.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yuan.domain.Nation;
import com.ruoyi.yuan.service.INationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 国家信息Controller
 * 
 * @author guifeng
 * @date 2022-08-25
 */
@Api("国家信息")
@RestController
@RequestMapping("/yuan/nation")
public class NationController extends BaseController
{
    @Autowired
    private INationService nationService;

    /**
     * 查询国家信息列表
     */
    @ApiOperation("查询国家信息列表")
    @PreAuthorize("@ss.hasPermi('yuan:nation:list')")
    @GetMapping("/list")
    public TableDataInfo list(Nation nation)
    {
        startPage();
        List<Nation> list = nationService.selectNationList(nation);
        return getDataTable(list);
    }

    /**
     * 导出国家信息列表
     */
    @ApiOperation("导出国家信息列表")
    @PreAuthorize("@ss.hasPermi('yuan:nation:export')")
    @Log(title = "国家信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Nation nation)
    {
        List<Nation> list = nationService.selectNationList(nation);
        ExcelUtil<Nation> util = new ExcelUtil<Nation>(Nation.class);
        util.exportExcel(response, list, "国家信息数据");
    }

    /**
     * 获取国家信息详细信息
     */
    @ApiOperation("获取国家信息详细信息")
    @PreAuthorize("@ss.hasPermi('yuan:nation:query')")
    @GetMapping(value = "/{nationId}")
    public AjaxResult getInfo(@PathVariable("nationId") Long nationId)
    {
        return AjaxResult.success(nationService.selectNationByNationId(nationId));
    }

    /**
     * 新增国家信息
     */
    @ApiOperation("新增国家信息")
    @PreAuthorize("@ss.hasPermi('yuan:nation:add')")
    @Log(title = "国家信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Nation nation)
    {
        return toAjax(nationService.insertNation(nation));
    }

    /**
     * 修改国家信息
     */
    @ApiOperation("修改国家信息")
    @PreAuthorize("@ss.hasPermi('yuan:nation:edit')")
    @Log(title = "国家信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Nation nation)
    {
        return toAjax(nationService.updateNation(nation));
    }

    /**
     * 删除国家信息
     */
    @ApiOperation("删除国家信息")
    @PreAuthorize("@ss.hasPermi('yuan:nation:remove')")
    @Log(title = "国家信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{nationIds}")
    public AjaxResult remove(@PathVariable Long[] nationIds)
    {
        return toAjax(nationService.deleteNationByNationIds(nationIds));
    }
}
